package com.example.service.impl;

import ch.qos.logback.classic.Logger;
import com.example.entity.AfterDo;
import com.example.mapp.AfterDoMapp;
import com.example.service.AfterDoService;
import com.example.util.ResultUtil;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by simon on 2018/12/4.
 */
@Service
public class AfterDoServiceImpl implements AfterDoService {

    private final static Logger logger = (Logger) LoggerFactory.getLogger(AfterDoServiceImpl.class);

    @Autowired
    AfterDoMapp afterDoMapp;

    @Override
    public Map<String, Object> deleteById(String id) {
        try{
            afterDoMapp.deleteById(id);
            return ResultUtil.returnSuccess("删除场景成功",null);
        }catch(Exception e){
            logger.error("删除场景失败",e);
            return ResultUtil.returnError("删除场景失败",null);
        }
    }

    @Override
    public Map<String, Object> add(AfterDo afterDo) {

        try{
            afterDoMapp.insert(afterDo);
            return ResultUtil.returnSuccess("创建场景成功",null);
        }catch(Exception e){
            logger.error("创建场景失败",e);
            return ResultUtil.returnError("创建场景失败",null);
        }
    }

    @Override
    public Map<String, Object> update(AfterDo afterDo) {
        try{
            afterDoMapp.update(afterDo);
            return ResultUtil.returnSuccess("更新场景成功",null);
        }catch(Exception e){
            logger.error("更新场景失败",e);
            return ResultUtil.returnError("更新场景失败",null);
        }
    }

    @Override
    public Map<String, Object> queryByType(AfterDo afterDo) {
        try{
            AfterDo afterDo1 = afterDoMapp.findByType(afterDo);
            Map res = new HashMap();
            res.put("afd", afterDo1);
            return ResultUtil.returnSuccess("查询场景成功",res);
        }catch(Exception e){
            logger.error("查询场景成功",e);
            return ResultUtil.returnError("查询场景失败",null);
        }
    }
}
